import { GeetConfig, LoginFormData, GoogleLoginData, LoginResponseData,GetVerificationCodeByEmailRes } from '@/types'
import request from '@/utils/request'
import { AxiosPromise } from 'axios'


// 参数接口
export interface RegisterByEmailParams {
	/*邮箱 */
	email: string;
  
	/*密码 */
	password: string;
  
	/*验证码 */
	validationCode: number;
  }
  
  // 响应接口
  export interface RegisterByEmailRes {
	/*状态码，请参考状态码手册 */
	code: number;
  
	/*响应结果 */
	data: Record<string, unknown>;
  
	/*响应信息 */
	msg: string;
  }
  
  /** 
   * 邮箱注册
   * @param {object} params userRegisterByEmailVO
   * @param {string} params.email 邮箱
   * @param {string} params.password 密码
   * @param {number} params.validationCode 验证码
   * @returns
   */
  export function registerByEmail(params: RegisterByEmailParams): AxiosPromise<RegisterByEmailRes> {
	return request.post(`/login/registerByEmail`, params);
  }

// 响应接口
export interface GetVerificationCodeByEmailRes {
	/*状态码，请参考状态码手册 */
	code: number;
  
	/*响应结果 */
	data: Record<string, unknown>;
  
	/*响应信息 */
	msg: string;
  }
/** 
 * 获取邮箱验证码
 * @param {string} email email
  * @returns
 */
export function getVerificationCodeByEmail(email: string): AxiosPromise<GetVerificationCodeByEmailRes> {
	return request.post(`/login/getVerificationCodeByEmail/${email}`);
  }


/**
 * 登录
 * @param data
 */
export function login(data: LoginFormData): AxiosPromise<LoginResponseData> {
	// return Promise.resolve({
	// 	username: 'admin'
	// })
	return request({
		url: 'api/users-info/login',
		method: 'post',
		data
	})
}

/**
 * 谷歌验证
 * @param data
 */
export function googleLogin(data: GoogleLoginData): AxiosPromise {
	return Promise.resolve({
		token: 'admin_token'
	})
	// return request({
	// 	url: '/google',
	// 	method: 'post',
	// 	data,
	//   extraConfig: { showFullscreenLoading: true }
	// })
}

/**
 * 注销
 */
export function logout() {
	return request({
		url: '/登出todo',
		method: 'delete'
	})
}

/**
 * Geetest配置参数
 */
export function getGeetConfig(): AxiosPromise<GeetConfig> {
	return request({
		url: `/passport/getgeetestconfig?t=${+new Date()}`,
		method: 'get'
	})
}
